package com.diorsunion.hedge.client.borker;

import com.diorsunion.hedge.dto.BorkerAccount;
import com.diorsunion.hedge.io.IOClient;
import com.diorsunion.hedge.io.Message;
import com.diorsunion.hedge.io.MessageType;
import com.google.common.collect.Maps;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;

/**
 * Created by custe on 2016/5/29.
 */
@Component
public class BorkerBO {
    @Resource
    IOClient ioClient;

    Map<Integer,BorkerCmd> cmdMap  = Maps.newConcurrentMap();

    public void addCmd(BorkerCmd borkerCmd){
        cmdMap.put(borkerCmd.id,borkerCmd);
    }

    public void onConnect(String accountId){
        BorkerAccount borkerAccount = new BorkerAccount();
        borkerAccount.accountId = accountId;
        //发送一个帐号登录的指令
        Message message = Message.genMessage(MessageType.Command,borkerAccount);
        ioClient.write(message);
    }
}
